<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('堆垛机执行队列列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        </li>
                        <li>
                            <label>任务号：</label>
                            <input type="text" name="taskNo"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm"
                               onclick="$.table.search('formId','bootstrap-table')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm"
                               onclick="$.form.reset('formId','bootstrap-table')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">

            <a class="btn btn-primary multiple disabled" onclick="reloadTask()">
                <i class="fa fa-edit"></i>&nbsp;重新下发</a>

            <a class="btn btn-danger multiple disabled" onclick="deleteTask()">
                <i class="fa fa-remove"></i>&nbsp;删除</a>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var ddjxfDatas = [[${@dict.getType('task_xf')}]];
    var rwlxDatas = [[${@dict.getType('dev_type')}]];
    var mlfsDatas = [[${@dict.getType('dev_mlfs')}]];
    var prefix = ctx + "device/tsjqueue";

    $(function () {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            reloadTaskUrl: prefix + "/reloadTask",
            deleteTaskUrl: prefix + "/deleteTask",
            modalName: "提升机执行队列",
            clickToSelect: true,//是否启用点击选中行
            uniqueId: "taskNo",//表主键(用于修改和删除)
            sortName: "devId",//必加排序 sortOrder: "asc"默认
            sortOrder: "asc",
            columns: [
                {
                    halign: 'center',
                    align: 'center',
                    checkbox: true
                },
                {
                    title: "序号",
                    halign: 'center',
                    align: 'center',
                    width: 55,
                    formatter: function (value, row, index) {
                        //获取每页显示的数量
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;

                    }
                },
                {
                    field: 'devId',
                    title: '设备编号',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'devName',
                    title: '设备名称',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'taskNo',
                    title: '任务号',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'yp',
                    title: '源排',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'yl',
                    title: '源列',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'mbp',
                    title: '目标排',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'mbl',
                    title: '目标列',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'zxjd',
                    title: '执行阶段',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'status',
                    title: '是否下发',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(ddjxfDatas, value);
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function reloadTask() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }

        $.modal.confirm("确认要重新下发选中的" + rows.length + "条任务吗?", function () {
            var url = table.options.reloadTaskUrl;
            var data = {"taskNo": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function deleteTask() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要删除选中的" + rows.length + "条任务吗?", function () {
            var url = table.options.deleteTaskUrl;
            var data = {"taskNo": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }
</script>
</body>
</html>